package com.itheima.demo;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {
    //获取SqlSessionFactoryBean对象
    @Bean
    public SqlSessionFactoryBean getSqlSessionFactoryBean(DataSource dataSource){
        SqlSessionFactoryBean ss = new SqlSessionFactoryBean();
        ss.setDataSource(dataSource);
        ss.setTypeAliasesPackage("com.itheima.domain");
        return ss;
    }

    //获取MapperScannerConfigurer对象
    @Bean
    public MapperScannerConfigurer getMapperScannerConfigurer(){
        MapperScannerConfigurer mc = new MapperScannerConfigurer();
        mc.setBasePackage("com.itheima.mapper");
        return mc;
    }
}
